import defaultAxios from 'axios';
import { message } from 'antd';
const axios = defaultAxios.create({
  baseURL: 'http://fangadmin.shbwyz.com',
});
const whiteList = [
  {
    method: 'get',
    url: '/servicerLog',
  },
  {
    method: 'get',
    url: '/chat',
  },
];
defaultAxios.interceptors.request.use((config): any => {
  config.headers.Authorization = localStorage.getItem('token')
    ? localStorage.getItem('token')
    : '';
  return config;
});
defaultAxios.interceptors.response.use((config) => {
  //响应成功之后判断 method url成功就响应成功
  console.log(config, 'res');
  const flag = whiteList.some(
    (item) =>
      item.method === config.config.method && item.url === config.config.url,
  );

  if (flag) {
    message.success('请求成功');
  }

  return config;
});
export { defaultAxios, axios };
